﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PlayerLoop;

public class Move_Toward : MonoBehaviour
{
    private Path keyPoint;
    private Transform target;
    public float speed = 1;
    void Start()
    {
        keyPoint = FindObjectOfType<Path>();
        target = keyPoint.keyPoint[Random.Range(0, 8)];
    }
    void Update()
    {
        transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * speed);
        if (transform.position==target.position)
        {
            target = keyPoint.keyPoint[Random.Range(0, 8)];
        }
    }
}
